package v2ray

import (
	core "github.com/v2fly/v2ray-core/v5"
	"github.com/v2fly/v2ray-core/v5/app/proxyman"
	_ "github.com/v2fly/v2ray-core/v5/app/proxyman/inbound"
	_ "github.com/v2fly/v2ray-core/v5/app/proxyman/outbound"
	"github.com/v2fly/v2ray-core/v5/common/net"
	"github.com/v2fly/v2ray-core/v5/common/protocol"
	"github.com/v2fly/v2ray-core/v5/common/serial"
	_ "github.com/v2fly/v2ray-core/v5/proxy/shadowsocks"
	_ "github.com/v2fly/v2ray-core/v5/proxy/shadowsocks/simplified"
	_ "github.com/v2fly/v2ray-core/v5/proxy/trojan/simplified"
	"github.com/v2fly/v2ray-core/v5/proxy/vmess"
	vmessout "github.com/v2fly/v2ray-core/v5/proxy/vmess/outbound"
	"github.com/v2fly/v2ray-core/v5/transport/internet"
	"github.com/v2fly/v2ray-core/v5/transport/internet/websocket"
)

func CreateOutboundHandlerConfig() *core.OutboundHandlerConfig {
	return &core.OutboundHandlerConfig{
		SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{
			StreamSettings: &internet.StreamConfig{
				ProtocolName: "websocket",
				TransportSettings: []*internet.TransportConfig{
					{
						Settings: serial.ToTypedMessage(&websocket.Config{
							Header: []*websocket.Header {
								{
									Key: "Host",
									Value: "imageakm1.tv360.vn",
								},
							},
						}),
					},
				},
				//SecurityType: serial.GetMessageType(&tls.Config{}),
				//SecuritySettings: []*anypb.Any{
				//	serial.ToTypedMessage(&tls.Config{
				//		AllowInsecure: true,
				//	}),
				//},
			},
		}),
		ProxySettings: serial.ToTypedMessage(&vmessout.Config{
			Receiver: []*protocol.ServerEndpoint{
				{
					Address: net.NewIPOrDomain(net.ParseAddress("158.101.7.8")),
					Port:    80,
					User: []*protocol.User{
						{
							Account: serial.ToTypedMessage(&vmess.Account{
								Id:      "95b45c49-f5c0-4959-bb64-2b8fbc4a869c",
								AlterId: 0,
								SecuritySettings: &protocol.SecurityConfig{
									Type: protocol.SecurityType_AUTO,
								},
							}),
						},
					},
				},
			},
		}),
	}
}

func CreateOutboundHandlerConfig2() *core.OutboundHandlerConfig {
	return &core.OutboundHandlerConfig{
		SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{
			StreamSettings: &internet.StreamConfig{
				ProtocolName: "websocket",
				TransportSettings: []*internet.TransportConfig{
					{
						Settings: serial.ToTypedMessage(&websocket.Config{
							Path: "/",
						}),
					},
				},
				//SecurityType: serial.GetMessageType(&tls.Config{}),
				//SecuritySettings: []*anypb.Any{
				//	serial.ToTypedMessage(&tls.Config{
				//		AllowInsecure: true,
				//	}),
				//},
			},
		}),
		ProxySettings: serial.ToTypedMessage(&vmessout.Config{
			Receiver: []*protocol.ServerEndpoint{
				{
					Address: net.NewIPOrDomain(net.ParseAddress("35.77.37.112")),
					Port:    12356,
					User: []*protocol.User{
						{
							Account: serial.ToTypedMessage(&vmess.Account{
								Id:      "c899fb95-cc39-4f3a-a882-36b70d4bef0f",
								AlterId: 0,
								SecuritySettings: &protocol.SecurityConfig{
									Type: protocol.SecurityType_AUTO,
								},
							}),
						},
					},
				},
			},
		}),
	}
}
